package com.ruoyi.project.common.recommend.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.common.recommend.domain.AppRecommend;
import com.ruoyi.project.common.recommend.service.IAppRecommendService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 换量系统Controller
 * 
 * @author shixiangwen
 * @date 2020-01-13
 */
@Controller
@RequestMapping("/common/recommend")
public class AppRecommendController extends BaseController
{
    private String prefix = "common/recommend";

    @Autowired
    private IAppRecommendService appRecommendService;

    @RequiresPermissions("common:recommend:view")
    @GetMapping()
    public String recommend()
    {
        return prefix + "/recommend";
    }

    /**
     * 查询换量系统列表
     */
    @RequiresPermissions("common:recommend:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppRecommend appRecommend)
    {
        startPage();
        List<AppRecommend> list = appRecommendService.selectAppRecommendList(appRecommend);
        return getDataTable(list);
    }

    /**
     * 导出换量系统列表
     */
    @RequiresPermissions("common:recommend:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppRecommend appRecommend)
    {
        List<AppRecommend> list = appRecommendService.selectAppRecommendList(appRecommend);
        ExcelUtil<AppRecommend> util = new ExcelUtil<AppRecommend>(AppRecommend.class);
        return util.exportExcel(list, "recommend");
    }

    /**
     * 新增换量系统
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存换量系统
     */
    @RequiresPermissions("common:recommend:add")
    @Log(title = "换量系统", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppRecommend appRecommend)
    {
        return toAjax(appRecommendService.insertAppRecommend(appRecommend));
    }

    /**
     * 修改换量系统
     */
    @GetMapping("/edit/{appid}")
    public String edit(@PathVariable("appid") Long appid, ModelMap mmap)
    {
        AppRecommend appRecommend = appRecommendService.selectAppRecommendById(appid);
        mmap.put("appRecommend", appRecommend);
        return prefix + "/edit";
    }

    /**
     * 修改保存换量系统
     */
    @RequiresPermissions("common:recommend:edit")
    @Log(title = "换量系统", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppRecommend appRecommend)
    {
        return toAjax(appRecommendService.updateAppRecommend(appRecommend));
    }

    /**
     * 删除换量系统
     */
    @RequiresPermissions("common:recommend:remove")
    @Log(title = "换量系统", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appRecommendService.deleteAppRecommendByIds(ids));
    }
}
